<template>
  <div class="outer">
    <div class="fr page">
      <div class="sui-pagination clearfix">
        <ul>
          <li
            class="prev"
            :disabled="pageNo == 1"
            @click="$emit('getpageNo', pageNo - 1)"
          >
            <a>«上一页</a>
          </li>
          <li
            v-if="pageNo - parseInt(continues / 2) >= 2"
            @click="$emit('getpageNo', 1)"
            :class="{ active: pageNo == 1 }"
          >
            <a>1</a>
          </li>
          <li class="dotted" v-if="pageNo - parseInt(continues / 2) >= 3">
            <span>...</span>
          </li>
          <li
            :class="{ active: pageNo == cont }"
            v-for="(cont, index) in statrNubEndNum"
            :key="index"
            v-if="cont > pageNo - parseInt(continues / 2) - 1"
            @click="$emit('getpageNo', cont)"
          >
            <a>{{ cont }}</a>
          </li>

          <li
            class="dotted"
            v-if="totalPage - pageNo > parseInt(continues / 2) + 1"
          >
            <span>...</span>
          </li>
          <li
            v-if="totalPage - pageNo > 3"
            @click="$emit('getpageNo', totalPage)"
            :class="{ active: pageNo == totalPage }"
          >
            <a>{{ totalPage }}</a>
          </li>
          <li
            class="next"
            :disabled="pageNo == totalPage"
            @click="$emit('getpageNo', pageNo + 1)"
          >
            <a>下一页»</a>
          </li>
          <div>
            <span>共{{ totalPage }}页&nbsp;</span>
          </div>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Page",
  props: ["pageSize", "continues", "total", "pageNo"],
  computed: {
    totalPage() {
      return Math.ceil(this.total / this.pageSize);
    },

    statrNubEndNum() {
      const { pageSize, continues, totalPage, pageNo } = this;
      let statr = 0;
      let end = 0;
      if (continues > totalPage) {
        statr = 1;
        end = totalPage;
      } else {
        statr = pageNo - parseInt(continues / 2);
        end = pageNo + parseInt(continues / 2);
        if (statr < 1) {
          statr = 1;
          end = continues;
        }
        if (end > totalPage) {
          statr = totalPage - continues;
          end = totalPage;
        }
      }
      return statr, end;
    },
  },
  methods: {},
};
</script>

<style scoped>
.outer .main .py-container .details .page {
  width: 1000px;
  height: 66px;
  overflow: hidden;
  float: right;
  text-align: center;
}
.outer .main .py-container .details .page .sui-pagination {
  margin: 18px 0;
}
.outer .main .py-container .details .page .sui-pagination ul {
  margin-left: 0;
  margin-bottom: 0;
  vertical-align: middle;
  width: 100%;
  float: left;
}
.outer .main .py-container .details .page .sui-pagination ul li {
  line-height: 18px;
  display: inline-block;
}
.outer .main .py-container .details .page .sui-pagination ul li a {
  position: relative;
  float: left;
  line-height: 18px;
  text-decoration: none;
  background-color: #fff;
  border: 1px solid #e0e9ee;
  margin-left: -1px;
  font-size: 14px;
  padding: 9px 18px;
  color: #333;
}
.outer .main .py-container .details .page .sui-pagination ul li.active a {
  background-color: #fff;
  color: #e1251b;
  border-color: #fff;
  cursor: default;
}
.outer .main .py-container .details .page .sui-pagination ul li.prev a {
  background-color: #fafafa;
}
.outer .main .py-container .details .page .sui-pagination ul li.disabled a {
  color: #999;
  cursor: default;
}
.outer .main .py-container .details .page .sui-pagination ul li.dotted span {
  margin-left: -1px;
  position: relative;
  float: left;
  line-height: 18px;
  text-decoration: none;
  background-color: #fff;
  font-size: 14px;
  border: 0;
  padding: 9px 18px;
  color: #333;
}
.outer .main .py-container .details .page .sui-pagination ul li.next a {
  background-color: #fafafa;
}
.outer .main .py-container .details .page .sui-pagination div {
  color: #333;
  font-size: 14px;
  float: right;
  width: 241px;
}
</style>
